package chw412;
import java.util.Comparator;

import pacworld.Location;

class Point implements Comparable<Point>, Comparator<Point>{
	  private int x;
	  private int y;
	  public Point parent = null;
	  public int gcost = 0;
	  public int fcost = 0;
	  
	  public static final int UNVISITED = 0;
	  public static final int VISITED = 1;
	  public boolean visited = false;
	  
	  public Point(int x, int y, Point parent) {
	    this.x = x;
	    this.y = y;
	    this.parent = parent;
	    gcost = 0;
	    fcost = 0;
	    visited = false;
	  }

	  public Point(Location l, Point parent) {
		  this.x = l.getX();
		  this.y = l.getY();
		  this.parent = parent;
		  gcost = 0;
		  fcost = 0;
		  visited = false;
	  }
	  
	  public int getX() {
	    return x;
	  }

	  public int getY() {
	    return y;
	  }
	  
	  public static int heuristic_cost_estimate(Point p, Point dest){
		  return Math.abs(p.getX() - dest.getX()) + Math.abs(p.getY() - dest.getY());
	  }

	  public int heuristic_cost_estimate(Point dest){
		  return Math.abs(this.getX() - dest.getX()) + Math.abs(this.getY() - dest.getY());
	  }
	  
	  public int dist(Point dest){
		  return Math.abs(this.getX() - dest.getX()) + Math.abs(this.getY() - dest.getY());
	  }
	  
	  @Override
	  public int compare(Point arg0, Point arg1) {
		  if(arg0.getX() - arg1.getX() < 0)
			  return -1;
		  else if(arg0.getX() - arg1.getX() > 0)
			  return 1;
		  else if(arg0.getY() - arg1.getY() < 0)
			  return -1;
		  else if(arg0.getY() - arg1.getY() > 0)
			  return 1;
		  return 0;
	  }

	  @Override
	  public int compareTo(Point o) {
		  if(this.getX() - o.getX() < 0)
			  return -1;
		  else if(this.getX() - o.getX() > 0)
			  return 1;
		  else if(this.getY() - o.getY() < 0)
			  return -1;
		  else if(this.getY() - o.getY() > 0)
			  return 1;
		  return 0;
	  }
};